package com.softqin.washer.fragment;

import java.util.ArrayList;
import java.util.List;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.RelativeLayout;

import com.softqin.washer.R;
import com.softqin.washer.activity.HomeOrderDetailActivity;
import com.softqin.washer.adapter.HomeOrderListAdapter;
import com.softqin.washer.bean.OrdersBean;
import com.softqin.washer.common.WasherApp;

/**
 * 
 * @ClassName: OrderFragment
 * 
 */ 
public class OrderFragment extends Fragment {
	private final static String TAG = "OrderFragment";

	private View mView_order;
	private boolean mIsLoad;
	private ListView orderListView = null;
	private List<OrdersBean> homeOrderBeans=null;
	private HomeOrderListAdapter homeOrderListAdapter;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		mView_order = inflater.inflate(R.layout.fragment_order, container);
		initView(mView_order);
		Log.i(TAG, "Order");
		return mView_order;
	}

	private void initView(View v) {
		orderListView = (ListView) v.findViewById(R.id.orderListView);
		homeOrderBeans=initData();
		Log.d("---", ""+homeOrderBeans.size());
		homeOrderListAdapter=new HomeOrderListAdapter(homeOrderBeans, this.getActivity());
		orderListView.setAdapter(homeOrderListAdapter);
		orderListView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				Intent intent=new Intent(OrderFragment.this.getActivity(), HomeOrderDetailActivity.class);
				startActivity(intent);
			}
		});
	}

	private List<OrdersBean> initData(){
		List<OrdersBean> list=new ArrayList<OrdersBean>();
		for (int i = 0; i < 10; i++) {
			OrdersBean bean=new OrdersBean();
			list.add(bean);
		}
		return list;
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
	}

	@Override
	public void onHiddenChanged(boolean hidden) {
		// TODO Auto-generated method stub
		super.onHiddenChanged(hidden);
		RelativeLayout rlFragmenOrder = (RelativeLayout) mView_order
				.findViewById(R.id.rl_fragment_order);
		rlFragmenOrder.setVisibility(View.VISIBLE);

		if (hidden && WasherApp.getInstance().mIHomepageBottomId != 2) {
			Log.i(TAG, "OrderFragment->this.isVisible()");
			mIsLoad = false;
		} else if (!mIsLoad) {
			Log.i(TAG, "");
			mIsLoad = true;
		}
	}

}
